package 异常处理;

import java.util.Calendar;
    //创建自定义异常（IllegalYearException）
  class IllegalYearException extends Exception
   {
	public IllegalYearException()
	{
		super("无效入职时间");
	}
   }
    //创建自定义异常（IllegalSalaryException）
  class IllegalSalaryException extends Exception
  {
	  String s;
	  public IllegalSalaryException(String str)
	  {
		  super(str);
		 
		  
	  }
  }
  
public class ExceptionDemoLab4_2 {
	
	//计算奖金
	public void sCa(int y,double s){
		
		if(y<1)
		{
			System.out.println("奖金为： "+s);
		}
		else if(y<=3)
		{
			System.out.println("奖金为："+s*1.3);
		}
		else if(y<5)
		{
			System.out.println("奖金为："+s*1.5);	
		}
		else if(y>5)
		{
			System.out.println("奖金为："+s*1.5);
		}
		
	}
	
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		//获取当前年份
		  Calendar now = Calendar.getInstance();  
	       int y2=now.get(Calendar.YEAR);
		//输入入职年份
		try
		{
		int y1=Integer.parseInt(args[0]);
		//计算入职时间
        int te=y2-y1;//出现te为负数，和输入值问题
        if(y1>y2||y1<0)
        {
        	throw new IllegalYearException();
        }
		//输入月工资
		double s1=Double.parseDouble(args[1]);
		if(s1<500||s1<0)
		{
			throw new IllegalSalaryException("无效月工资");
		}
		ExceptionDemoLab4_2 Lab=new ExceptionDemoLab4_2();
		Lab.sCa(te, s1);
		}
		catch(ArrayIndexOutOfBoundsException ex)
		{
			System.out.println("数组下标异常：请重新输入");
		}
		catch(NumberFormatException ex)
		{
			System.out.println("数字格式错误：请重新输入");
		}
		catch(IllegalYearException ex)
		{
			System.out.println(ex.getMessage());
		}
		catch(IllegalSalaryException ex)
		{
			System.out.println(ex.getMessage());
		}
		catch(Exception ex)
		{
			System.out.println("其他异常：请重新输入");
		}
		
	    

	}

}
